package com.example.sihookuiklydemo.bean

import com.tencent.kuikly.core.nvi.serialization.json.JSONArray
import com.tencent.kuikly.core.nvi.serialization.json.JSONObject


data class DeskModeQuery(
    val equipmentId: Int,
    val token: String,
    val userId: Int
)

/*
data class DeskQueryResult(
    val code: Int,

    val content: Content,
    val msg: String,

    val tokenInvalidReason: JsonElement
)
@Serializable
data class Content(
    val equipmentArray: List<EquipmentArray>,
    val equipmentBindingHistoryArray: List<EquipmentBindingHistoryArray>
)
@Serializable
data class EquipmentArray(
    val assembleProductKey: JsonElement?,
    val bindTime: String?,
    val bindTimeUtc: Long?,
    val btBleName: String?,
    val clientIp: JsonElement?,
    val color: String?,
    val customDeskModeJson: List<CustomDeskModeJson>?,
    val equipmentId: Int?,
    val equipmentType: Int?,
    val firmwareVersion1: String?,
    val hardwareVersion: String?,
    val isNewUserBind: JsonElement?,
    val isOnline: Boolean?,
    val isRecentlyOnline: Boolean?,
    val macAddress: String?,
    val macAddressBtClassic: JsonElement?,
    val name: String?,
    val nameV2: String?,
    val pairToken: String?,
    val productKey: String?,
    val realSpu: String?,
    val sn: String?,
    val spu: String?
)
@Serializable
data class EquipmentBindingHistoryArray(
    val bindTime: String?,
    val bindTimeUtc: Long?,
    val equipmentId: Int?,
    val equipmentType: Int?,
    val name: String?,
    val nameV2: String?,
    val spu: String?
)
@Serializable
*/
class CustomDeskModeJson(

) {
    var custom: Int? = null
    var isAuto: Boolean? = null
    var isSelected: Boolean? = null
    var name: String? = null
    var sit: Int? = null
    var stand: Int? = null
    fun decode(itemJSONObject: JSONObject): CustomDeskModeJson {
        custom = itemJSONObject.optInt("custom")
        isAuto = itemJSONObject.optBoolean("isAuto")
        isSelected = itemJSONObject.optBoolean("isSelected")
        name = itemJSONObject.optString("name")
        sit = itemJSONObject.optInt("sit")
        stand = itemJSONObject.optInt("stand")
        return this
    }
}

fun getDeskModeList(content: JSONObject): ArrayList<CustomDeskModeJson> {
    var deskModeList = ArrayList<CustomDeskModeJson>()
    var customDeskModeJson =
        content
            ?.optJSONArray("customDeskModeJson")
    customDeskModeJson?.let {
        var deskSize = it.length()
        for (j in 0 until deskSize) {
            deskModeList.add(
                CustomDeskModeJson().decode(
                    customDeskModeJson.optJSONObject(
                        j
                    ) ?: JSONObject()
                )
            )
        }

    }
    return deskModeList
}